<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <title>我的</title>
    <meta name="format-detection" content="telephone=no" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="../css/bui.css" />
    <link rel="stylesheet" href="../font2/iconfont.css" />
</head>
<body>
<style type="text/css">
    .personal-header {
        margin-top: 10px;
        margin-left: 5px;
        margin-right: 5px;
        border-radius: 10px;
        background-color: #39a4ff;
        /*background-image: linear-gradient(to bottom, #7cb8e9, #89bfe3, #72a8d7, #89b5d8, #92bbda);*/
        padding-top: .3rem;
        padding-bottom: .3rem;
    }

    .personal-header .personal-img {
        width: 1.5rem;
        height: 1.5rem;
        border-radius: 50%;
        /*background:#fff;*/
        /* border: 2px solid #fff; */
        overflow: hidden;
        margin: 0 auto .2rem auto;
        text-align: center;
    }

    .personal-header .personal-img img {
        width: 100%;
    }

    .personal-header p {
        text-align: center;
        color: #ffffff;
        margin-bottom: 0.1rem;
    }

    .personal-header .name {
        font-size: 0.26rem;
    }

    .personal-header .grade {
        font-size: 0.2rem;
    }

    .nav-list {
        border-top: none;
        margin-top: 0.2rem;
        padding: 0 0.2rem;
        background-color: #ffffff;
    }

    .nav-list .bui-btn {
        padding-left: 0;
        padding-right: 0;
    }

    .nav-list li:first-child {
        border-top: none;
    }

    .nav-list .icon i {
        font-size: 0.4rem;
    }

    .nav-list .icon {
        height: 0.42rem;
    }

    .nav-list .bui-btn {
        border: none;
        border-top: 1px solid #efefef;
    }

    .icon-yellow {
        color: #ffad03;
    }

    .icon-thinblue {
        color: #56ced5;
    }

    .icon-green {
        color: #6ed046;
    }

    .icon-red {
        color: #fd8886;
    }
    .main-footer {
        background-color: #fff
    }

    .main-footer .btn-home {
        position: relative;
        overflow: visible
    }

    .main-footer .btn-home .big-icon {
        z-index: 10;
        margin-top: -.2rem;
        display: inline-block;
        width: .94rem;
        height: .94rem;
        line-height: .94rem;
        color: #fff;
        border-radius: 50%;
        background: linear-gradient(141.4deg, #02b9fa, #508dff)
    }
    .main-footer .layer1 {
        top: -.3rem;
        left: 50%;
        width: 1.2rem;
        height: 1.2rem;
        position: absolute;
        box-shadow: 0 0 1px 1px #eee;
        border-radius: 50%;
        transform: translateX(-50%);
        background-color: #fff
    }

    .main-footer .layer2 {
        position: absolute;
        top: 0rem;
        bottom: -.05rem;
        width: 100%;
        background-color: #fff
    }
</style>

<div class="bui-page">
    <header class="bui-bar">
        <div class="bui-bar-left">
<!--            <a class="bui-btn btn-back"><i class="icon-back"></i></a>-->
        </div>
        <div class="bui-bar-main">个人中心</div>
        <div class="bui-bar-right">
        </div>
    </header>
    <main>
        <div class="personal-header" id="qbdiv" style="display: none">
<!--            <div class="personal-img">-->
<!--                <img src="../images/pig.png">-->
<!--            </div>-->
<!--            <p class="name">-->
<!--                钱包-->
<!--            </p>-->
            <div style="color: white;margin-left: 10px">
                钱包
            </div>

            <div class="bui-box-align-middle" style="color: white;margin-left: 10px;margin-top: 10px">
                <div class="span1">
                    <h1 id="qianbao_yue"></h1>
                </div>
                <div class="span2">
                    <h5 id="qianbao_tixian"></h5>
                </div>
                <div class="span1">
                    <input type="button" id="chognzhi" style="width: 80px;color: black;font-size: .27rem" value="充值"/><br>
                    <input type="button" id="tixian" style="width: 80px;color: black;margin-top: 5px;font-size: .27rem" value="提现"/>
                </div>
            </div>

<!--            <p class="grade">积分：2988</p>-->
        </div>

        <ul class="bui-list nav-list ">
            <li class="bui-btn bui-box " href="./bank.html" id="bankdiv" style="display: none">
                <div class="icon">
                    <span class="iconfont icons-yinhangka" style="color: red"></span>
                </div>
                <div class="span1">银行卡管理</div>
                <i class="icon-listright"></i>
            </li>

            <li class="bui-btn bui-box" href="./chongzhi.html" id="czdiv" style="display: none">

                <div class="icon">
                    <span class="iconfont icons-chongzhijilu" style="color: forestgreen"></span>
                </div>
<!--                    <i class="icon icon-green">&#xe612;</i></div>-->
                <div class="span1">充值记录</div>
                <i class="icon-listright"></i>
            </li>
            <li class="bui-btn bui-box" href="./tixian.html" id="txdiv" style="display: none">
                <div class="icon">
                    <span class="iconfont icons-tixianjilu" style="color: deepskyblue"></span>
                </div>
                <div class="span1">提现记录</div>
                <i class="icon-listright"></i>
            </li>

            <li class="bui-btn bui-box " href="./grxx.html">
                <div class="icon"><i class="icon-favfill icon-yellow"></i></div>
                <div class="span1">个人信息</div>
                <i class="icon-listright"></i>
            </li>

            <li class="bui-btn bui-box" href="./version.html">
                <div class="icon"><i class="icon icon-green">&#xe62d;</i></div>
                <div class="span1">版本信息</div>
                <i class="icon-listright"></i>
            </li>

            <div class="bui-interval">

                <div class="bui-btn large ring primary" id="logout" href="#">退出登录</div>
            </div>
        </ul>

        <div id="dialogCenter" class="bui-dialog" style="display: none;">
            <div class="bui-dialog-head">手机验证码验证</div>
            <div class="bui-dialog-main">
                <label class="bui-btn bui-box clearactive">
                    <label class="bui-label">手机号:</label>
                    <div class="span1">
                        <input type="text" id="receivemobile" class="bui-input" readonly="readonly">
                        <input type="hidden" id="messageorderno">
                        <input type="hidden" id="memberacctno">
                        <input type="hidden" id="tranamt">
                        <input type="hidden" id="takecashacctno">
                        <input type="hidden" id="takecashacctname">
                    </div>
                </label>
                <label class="bui-btn bui-box clearactive">
                    <label class="bui-label">验证码:</label>
                    <div class="span1">
                        <input type="text" id="messagecheckcode" class="bui-input" value="" placeholder="请输入验证码" maxlength="6">
                    </div>
                    <div class="bui-btn primary-reverse mini ring" id="btnSend">发送验证码</div>
                </label>
            </div>
            <div class="bui-dialog-foot">
                <div class="bui-box">
                    <div class="span1">
                        <div id="bindsmscancel" class="bui-btn">取消</div>
                    </div>
                    <div class="span1">
                        <div id="bindsmsok" class="bui-btn blue">确定</div>
                    </div>
                </div>
            </div>
            <div class="bui-dialog-close"><i class="icon-close"></i></div>
        </div>



    </main>

    <footer class="main-footer">
        <!-- 底部d导航栏 -->
        <ul class="bui-nav">
            <li class="bui-btn bui-box-vertical" id="homeButton"><i class="icon-home"></i>
                <div class="span1">首页</div>
            </li>
            <li class="bui-btn btn-home bui-box-vertical" id="btnAdd">
                <i class="icon-plus big-icon"></i>
                <span class="layer1"></span><span class="layer2"></span>
            </li>
            <li class="bui-btn bui-box-vertical active"><i class="icon">&#xe67a;</i>
                <div class="span1">我的</div>
            </li>
        </ul>
    </footer>
</div>

    <!-- 依赖库 手机调试的js引用顺序如下 -->
    <script src="../js/zepto.js"></script>
    <script src="../js/plugins/fastclick.js"></script>
    <script src="../js/bui.js"></script>
    <script src="../js/common.js"></script>
    <script>

        bui.ready(function () {
            // 这里写业务及控件初始化
            bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();

            $("#chognzhi").hide();
            $("#tixian").hide();

            initCommon(bui);
            var lx = $$("lx");
            // console.log(lx);
            var yhbm = $$("yhbm");
            if(lx == 2){
                $("#btnAdd").hide();
            }
            if(lx == 3){
                $("#qbdiv").show();
                $("#bankdiv").show();
                $("#czdiv").show();
                $("#txdiv").show();
            }else{
                $("#qbdiv").hide();
                $("#bankdiv").hide();
                $("#czdiv").hide();
                $("#txdiv").hide();
            }
            var storage = bui.storage();
            var user = storage.get("user",0);
            var lx = storage.get("lx");
            if(lx == 2 || lx == 0 || lx==3){
                $("#btnAdd").hide();
            }

            $("#homeButton").on("click",function (data) {
                window.location.href = "home.html";
            });

            $("#logout").on("click", function (argument) {
                var storage = bui.storage();
                storage.clear();
                bui.load({ url: "../index.html"});
            });

            $("#btnAdd").on("click",function () {
                bui.confirm("确认要发起订单么？", function(e) {
                    var text = $(e.target).text();
                    if (text == "确定") {
                        //执行登录操作

                        var addAjax = bui.ajax({
                            url: BASE_URL+"/front/addOrder",
                            // 可选参数
                            data: {
                                yhbm:yhbm
                            },
                            method: "POST"
                        });
                        addAjax.then(function(res) {
                            if(res.code == 0){
                                var user = res.data;
                                bui.alert("订单发起成功");
                                window.location.reload();
                            }else{
                                bui.alert(res.msg);
                            }
                        },function(res) {
                            bui.alert("请求异常");
                        })
                        // console.log("你点击了" + $(e.target).text())
                    }
                    this.close()
                });
            });
            if(lx == 3) {
                var bindCardAjax = bui.ajax({
                    url: BASE_URL+"/front/bindcardcztx",
                    // 可选参数
                    data: {
                        yhbm:yhbm
                    },
                    method: "GET"
                });
                bindCardAjax.then(function(res) {
                    if(res.code == 0){
                        if(res.data.bindcard_cz=='1'){
                            $("#chognzhi").show();
                        }
                        if(res.data.bindcard_tx=='1'){
                            $("#tixian").show();
                        }
                    }
                },function(res) {
                    bui.alert("请求异常");
                });

                // console.log("xm:"+user);
                if (user) {
                    $("#xm").html(user.xm);

                    //获取余额
                    var qianbaoAjax = bui.ajax({
                        url: BASE_URL + "ysk/pay/getqianbao",
                        data: {
                            // yhbm: user.yhbm,
                            // subacctno: user.subno
                            membercode:user.membercode,
                            // memberacctno:bindcardno,
                        },
                        method: "GET"
                    });
                    qianbaoAjax.then(function (res) {
                        if (res.code == 0) {
                            var qianbao = res.data;
                            if (qianbao) {
                                $("#qianbao_yue").html("<strong>￥" + qianbao.acctavailbal + "</strong>");
                                $("#qianbao_tixian").html("可提现￥" + qianbao.cashamt);
                            }
                        }
                    }, function (res) {
                        bui.alert("请求异常");
                    });

                }


                var timer = bui.timer({
                    onEnd: function () {
                        bui.alert("验证码已超期，请重新提交获取验证码！");
                        uiDialog.close();
                    },
                    onProcess: function (e) {
                        var valWithZero = e.count < 120 ? "0" + e.count : e.count;
                        $btnSend.text(valWithZero + "后重新获取");
                    },
                    time: 120
                });

                //获取选择提现银行卡
                var uiActionsheet;
                var yhkAjax = bui.ajax({
                    url: BASE_URL + "front/tixianyhklist?yhbm=" + $$("yhbm"),
                    method: "GET"
                });
                yhkAjax.then(function (res) {
                    if (res.code == 0) {
                        uiActionsheet = bui.actionsheet({
                            trigger: "#tixian",
                            buttons: res.data,
                            callback: yhk_todo
                        });

                        function yhk_todo(e) {
                            var val = $(e.target).attr("value");
                            if( val == "cancel"){
                                this.hide();
                                return ;
                            }
                            this.hide();
                            var select_value = $(e.target).attr("value");
                            var select_ary = select_value.split("_");
                            var takecashacctno = select_ary[1];
                            var takecashacctname = select_ary[0];

                            // console.log('select_value:'+select_value);
                            // console.log('takecashacctno:'+takecashacctno);
                            // console.log('takecashacctname:'+takecashacctname);
                            var uiPrompt = bui.prompt("请输入提现金额", function (e) {
                                var text = $(e.target).text();
                                if (text == "取消") {
                                    this.close();
                                } else {
                                    if (this.value()) {
                                        // 获取输入的值
                                        var tranamt = this.value();
                                        // bui.hint("您好,"+this.value());
                                        this.close();

                                        //发起获取短信验证码
                                        var tixiansmsAjax = bui.ajax({
                                            url: BASE_URL + "ysk/pay/gettixiansmscode",
                                            data: {
                                                subacctno: user.subno,
                                                membercode: user.membercode,
                                                memberacctno: takecashacctno,
                                                tranamt: tranamt,
                                            },
                                            method: "POST"
                                        });
                                        tixiansmsAjax.then(function (res) {
                                            var receivemobile = res.data.receivemobile;
                                            var messageorderno = res.data.messageorderno;
                                            $("#tranamt").val(tranamt);
                                            $("#takecashacctno").val(takecashacctno);
                                            $("#takecashacctname").val(takecashacctname);
                                            $("#receivemobile").val(receivemobile);
                                            $("#messageorderno").val(messageorderno);
                                            $("#messagecheckcode").val('');

                                            if (res.code == '0') {

                                                uiDialog.open();
                                                var hasDisabled = $btnSend.hasClass("disabled");
                                                if (!hasDisabled) {
                                                    $btnSend.addClass("disabled");
                                                    bui.hint("验证码发送成功");
                                                    // timer.restart();
                                                }

                                            } else {
                                                bui.alert(res.msg, function (e) {

                                                });
                                            }

                                        }, function (res) {
                                            bui.alert("请求异常");
                                        });

                                    } else {
                                        bui.hint("提现金额不能为空");
                                    }
                                }
                            })

                        }
                    }
                }, function (res) {
                    bui.alert("请求异常");
                });


                $("#chognzhi").on("click", function (argument) {
                    var uiPrompt = bui.prompt("请输入充值金额（元）", function (e) {
                        var text = $(e.target).text();
                        if (text == "取消") {
                            this.close();
                        } else {
                            if (this.value()) {
                                // 获取输入的值
                                // bui.hint("您好," + this.value());
                                var tranamt = parseFloat(this.value()) * 100;
                                window.location.href = "/ysksdk/cashierDesk?membercode=" + $$("membercode") + "&subno=" + user.subno + "&tranamt=" + tranamt,
                                    this.close();
                            } else {
                                bui.hint("充值金额不能为空");
                            }
                        }
                    })
                });

                // $("#tixian").on("click",function (argument) {
                // });

                var $btnSend = $("#btnSend");
                var uiDialog = bui.dialog({
                    id: "#dialogCenter",
                    height: 300,
                    autoClose: false,
                    callback: function (e) {
                    }
                }).on("open", function () {
                    if (timer) {
                        timer.start();
                        timer = null;
                    }
                });

                $("#bindsmsok").on("click", function () {
                    var tranamt = $("#tranamt").val();
                    var takecashacctno = $("#takecashacctno").val();
                    var takecashacctname = $("#takecashacctname").val();
                    // var receivemobile = $("#receivemobile").val();
                    var messageorderno = $("#messageorderno").val();
                    var messagecheckcode = $("#messagecheckcode").val();

                    if (messagecheckcode != '') {
                        var bindsmsAjax = bui.ajax({
                            url: BASE_URL + "ysk/pay/gettixianprocess",
                            data: {
                                subacctno: user.subno,
                                subacctname: user.xm,
                                membercode: user.membercode,
                                takecashacctno: takecashacctno,
                                takecashacctname: takecashacctname,
                                tranamt: tranamt,
                                messageorderno: messageorderno,
                                messagecheckcode: messagecheckcode
                            },
                            method: "POST"
                        });
                        bindsmsAjax.then(function (res) {
                            if (res.code == '0') {
                                bui.alert("提现成功！", function (e) {
                                    window.location.href = "my.html";
                                });
                            } else {
                                bui.alert(res.msg, function (e) {
                                    uiDialog.close();
                                });
                            }

                        }, function (res) {
                            bui.alert("请求异常");
                        });

                    }
                });

                $("#bindsmscancel").on("click", function () {
                    uiDialog.close();
                });
            }

        })
    </script>
</body>
</html>